package 
{
	import flash.display.*;
	import flash.events.*;
	import flash.ui.Keyboard;
	
	import org.flashbrighton.as3bots.controllers.GameController;
	import org.flashbrighton.as3bots.models.GameModel;
	import org.flashbrighton.as3bots.views.GameView;
	
	[SWF(width="1024", height="700", frameRate="60")] //backgroundColor="#000000"
	
	public class Main extends Sprite
	{
		private var _model:GameModel;
		private var _controller:GameController;
		private var _view:GameView;
			
		public function Main()
		{
			setStage();
			setGame();
			enableKeys();
		}
		
		
		private function setStage():void
		{
			stage.scaleMode = StageScaleMode.NO_SCALE;
			stage.align = StageAlign.TOP_LEFT;
		}
		
		
		private function setGame():void
		{
			/*_model = new GameModel();
			_controller = new GameController(_model);
			_view = new GameView(_model, _controller);*/
			
			_model = new GameModel();
			_view = new GameView(_model);
			_controller = new GameController(_model, _view);
			
			addChild(_view);
		}
		
		
		private function enableKeys():void
 		{
 			stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
 			stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
 		} 		
 		
 		private function onKeyDown(k:KeyboardEvent):void
 		{ 			
 			switch (k.keyCode)
 			{
 				case Keyboard.UP:
 				_controller.debugBot.m_userData.logic._engineVal = 1.0;
 				break;
 				
 				case Keyboard.DOWN:
 				_controller.debugBot.m_userData.logic._engineVal = -1.0;
 				break;
 				
 				case Keyboard.LEFT:
 				_controller.debugBot.m_userData.logic._rotationVal = -1.0;
 				break;
 				
 				case Keyboard.RIGHT:
 				_controller.debugBot.m_userData.logic._rotationVal = 1.0;
 				break;
 			}
 		}
 		
 		private function onKeyUp(k:KeyboardEvent):void
 		{
 			if (k.keyCode == Keyboard.UP || k.keyCode == Keyboard.DOWN)
 			{
 				_controller.debugBot.m_userData.logic._engineVal = 0;
 			}
 			
 			if (k.keyCode == Keyboard.LEFT || k.keyCode == Keyboard.RIGHT)
 			{
 				_controller.debugBot.m_userData.logic._rotationVal = 0;
 			}			
 		}
 		
	}
	
}
